package com.zzyl.service.impl;

import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.DeviceDataPageReqDto;
import com.zzyl.mapper.DeviceDataMapper;
import com.zzyl.service.DeviceDataService;
import com.zzyl.vo.DeviceDataVo;
import org.springframework.beans.factory.annotation.Autowired;
import com.github.pagehelper.Page;

import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class DeviceDataServiceImpl implements DeviceDataService {
    @Autowired
    private DeviceDataMapper deviceDataMapper;
    @Override
    public PageResponse<DeviceDataVo> getPage(DeviceDataPageReqDto deviceDataPageReqDto) {
        LocalDateTime startDate = deviceDataPageReqDto.getStartDate();
        LocalDateTime endDate = deviceDataPageReqDto.getEndDate();
        PageHelper.startPage(deviceDataPageReqDto.getPageNum(),deviceDataPageReqDto.getPageSize());
        Page<DeviceDataVo> page = deviceDataMapper.getPage(deviceDataPageReqDto.getDeviceName(),deviceDataPageReqDto.getFunctionId(),startDate,endDate);
        PageResponse<DeviceDataVo> pageResponse = PageResponse.of(page, DeviceDataVo.class);
        return pageResponse;
    }
}
